// 获取本市仓库ID
var info = null;
var userGlobalInfo = app.getUserGlobalInfo();
var managerGlobalInfo = app.getManagerGlobalInfo();
if (userGlobalInfo) {
  info = userGlobalInfo;
} else {
  info = managerGlobalInfo;
}
// console.log(info);

// 本市仓库盘点
$("#cityInventoryBtn").click(function () {
  var repositoryId = info.repositoryList[0].repositoryId;
  // console.log(repositoryId);
  var categoryId = $("#citySelect option:selected").val();;
  // console.log(categoryId);
  var inventoryCityDate = localStorage.getItem("inventoryCityDate");
  // console.log(inventoryCityDate);
  if (categoryId == "" || inventoryCityDate == "") {
    layer.msg("请先选择盘点信息！");
  } else {
    $.ajax({
      url: app.ServerUrl + 'repositoryLog/getRepositoryLogByMonth',
      type: "get",
      contentType: "application/json;charset=UTF-8",
      dataType: "json",
      async: true,
      headers: {
        "Authorization": "460bcdb0-b326-4d6d-ac99-232c83ba6d80"
      },
      data: {
        categoryId: categoryId,
        date: inventoryCityDate,
        repositoryId: repositoryId
      },
      beforeSend: function () {
        loading = layer.load();
      },
      success: function (data) {
        layer.close(loading);
        // console.log(data.objs[0]);
        var results = data.objs[0];
        $("#tbody").empty();
        if (results.length == 0) {
          layer.msg('暂无记录');
          var str = `
          <tr>
          <td>暂无</td>
          <td>暂无</td>
          <td>暂无</td>
          <td>暂无</td>
          <td>暂无</td>
          <td>暂无</td>
        </tr>`
        } else {
          var Nums = null;
          var Expand = null;
          var Destory = null;
          var str = '';

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            // console.log(item);

            if (item.categoryId == "1") {
              Nums = item.terminalNums;
              Expand = item.terminalExpand;
              Destory = item.terminalDestory;
            } else if (item.categoryId == "2") {
              Nums = item.equipmentNums;
              Expand = item.equipmentExpand;
              Destory = item.equipmentDestory;
            } else {
              Nums = item.stuffNums;
              Expand = item.stuffExpand;
              Destory = item.stuffDestory;
            }
            str +=
              `<tr>
              <td>${item.typicalName}</td>
              <td>${item.brand}</td>
              <td>${item.typicalModel}</td>
              <td>${Nums}</td>
              <td>${Expand}</td>
              <td>${Destory}</td>
            </tr>`
          }
        }
        $("#tbody").append(str);
      },
      error: function (e) {
        console.log(e.statusText)
      }
    })
  }

})